// Fill out your copyright notice in the Description page of Project Settings.

#include "Barid.h"
#include "Components\CapsuleComponent.h"
#include "Components\SkeletalMeshComponent.h"
#include "GameFramework\SpringArmComponent.h"
#include "Camera/CameraComponent.h"

// Sets default values
ABarid::ABarid()
{
 	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	Capsule = CreateDefaultSubobject<UCapsuleComponent>(TEXT("Capsule"));
	Capsule->SetCapsuleHalfHeight(18.f);
	Capsule->SetCapsuleRadius(12.f);
	SetRootComponent(Capsule);

	BridMash = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("BridMash"));
	BridMash->SetupAttachment(GetRootComponent());

	SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));
	SpringArm->SetupAttachment(GetRootComponent());
	SpringArm->TargetArmLength = 300.f;

	ViewCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("ViewCamera"));
	ViewCamera->SetupAttachment(SpringArm);

	AutoPossessPlayer = EAutoReceiveInput::Player0;
	
}

// Called when the game starts or when spawned
void ABarid::BeginPlay()
{
	Super::BeginPlay();
	
}

void ABarid::MoveForward(float Value)
{
	if ((Controller != nullptr) && (Value!=0))
	{
		FVector Forward = GetActorForwardVector();
		AddMovementInput(Forward, Value);
	}
}

void ABarid::Turn(float Value)
{
	if ((Controller != nullptr) && (Value != 0))
	{
		AddControllerYawInput(Value);
	}
}

void ABarid::Lookup(float Value)
{
	if ((Controller != nullptr) && (Value != 0))
	{
		AddControllerPitchInput(Value);
	}
}

// Called every frame
void ABarid::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void ABarid::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	PlayerInputComponent->BindAxis(FName("MoveForward"), this, &ABarid::MoveForward);
	PlayerInputComponent->BindAxis(FName("Turn"), this, &ABarid::Turn);
	PlayerInputComponent->BindAxis(FName("Lookup"), this, &ABarid::Lookup);

}

